/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer 58 - II. 左旋转字符串
 * @author: WXY
 * @create: 2022-12-10 22:08
 * @Version 1.0
 **/


public class Num058_2_reverseLeftWords {
    public static String reverseLeftWords(String s, int k) {
        if (s.length() == 0) {
            return "";
        }
        char[] str = s.toCharArray();
        int len = str.length - 1;
        swapWords(str, 0, len);
        swapWords(str, 0, len - k);
        swapWords(str, len - k + 1, len);
        return new String(str);
    }

    private static void swapWords(char[] str, int l, int r) {
        while (l < r) {
            char ch = str[l];
            str[l] = str[r];
            str[r] = ch;
            l++;
            r--;
        }
    }

    public static void main(String[] args) {
        String S = reverseLeftWords("abcdeasdfsadffg", 6);
        System.out.println(S);
    }
}
